package com.liyujie.networkrequest.utils.popup;

import android.content.Context;

import com.blankj.utilcode.util.ThreadUtils;
import com.liyujie.networkrequest.listener.BeCommonCallback;
import com.liyujie.networkrequest.pop.AwaitTipsPopup;
import com.liyujie.networkrequest.pop.DoorOpenPopup;
import com.liyujie.networkrequest.pop.ScanQRCodesPopup;
import com.liyujie.networkrequest.pop.SwipeCardPopup;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
/**
 * 全部弹框
 */
public class PopupUtils {

    /**
     * 等待提示
     */
    private static AwaitTipsPopup mAwaitTipsPopup;

    /**
     * 显示
     */
    public static void showAwaitTipsPopup(Context mContext,String SettingsContent){
        mAwaitTipsPopup = new AwaitTipsPopup(mContext,SettingsContent);
        new XPopup
                .Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mAwaitTipsPopup)
                .show();
    }


    /**
     * 关闭弹框
     */
    public static void dismissAwaitTipsPopup(){
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(null != mAwaitTipsPopup){
                    mAwaitTipsPopup.dismiss();
                }
            }
        });

    }


    /**
     * 扫码
     */
    private static ScanQRCodesPopup mScanQRCodesPopup;

    public static void showScanQRCodesPopup(Context mContext, BeCommonCallback beCommonCallback){
        mScanQRCodesPopup = new ScanQRCodesPopup(mContext);
        mScanQRCodesPopup.setBeCommonCallback(beCommonCallback);
        new XPopup
                .Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mScanQRCodesPopup)
                .show();
    }


    /**
     * 扫码关闭弹框
     */
    public static void dismissScanQRCodesPopup(){
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(null != mScanQRCodesPopup){
                    mScanQRCodesPopup.dismiss();
                }
            }
        });

    }

    /**
     * 刷卡
     */
    private static SwipeCardPopup mSwipeCardPopup;
    public static void showSwipeCardPopup(Context mContext, BeCommonCallback beCommonCallback){
        mSwipeCardPopup = new SwipeCardPopup(mContext);
        mSwipeCardPopup.setBeCommonCallback(beCommonCallback);
        new XPopup
                .Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mSwipeCardPopup)
                .show();
    }

    /**
     * 刷卡关闭弹框
     */
    public static void dismissSwipeCardPopup(){
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(null != mSwipeCardPopup){
                    mSwipeCardPopup.dismiss();
                }
            }
        });

    }


    /**
     * 开门成功
     */
    private static DoorOpenPopup mDoorOpenPopup;
    public static void showDoorOpenPopup(Context mContext,int boxNum){
        mDoorOpenPopup = new DoorOpenPopup(mContext,boxNum);
        new XPopup
                .Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mDoorOpenPopup)
                .show();
    }

    /**
     * 开门成功关闭弹框
     */
    public static void dismissDoorOpenPopup(){
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(null != mDoorOpenPopup){
                    mDoorOpenPopup.dismiss();
                }
            }
        });

    }
}
